package model.domain;


import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;


@Entity
@Table(name = "user", catalog = "scrum", uniqueConstraints = @UniqueConstraint(columnNames = "cLogin"))
public class Person implements java.io.Serializable {

	/**
	 * Default serial version ID generated by Eclipse
	 */
	private static final long serialVersionUID = 1L;
	private Integer personID;
	private Role role;
	private Status status;
	private String firstName;
	private String lastName;
	private String login;
	private String password;
	private Set<Impediment> impediments = new HashSet<Impediment>(0);
	private Set<Task> sprintbacklogs = new HashSet<Task>(0);
	private Set<ProjectParticipation> projectparticipations = new HashSet<ProjectParticipation>(0);

	public Person() {
	}

	public Person(Role role, Status status, String firstName, String lastName,
			String login) {
		this.role = role;
		this.status = status;
		this.firstName = firstName;
		this.lastName = lastName;
		this.login = login;
	}

	public Person(Role role, Status status, String firstName, String lastName,
			String login, String password, Set<Impediment> impediments,
			Set<Task> sprintbacklogs, Set<ProjectParticipation> projectparticipations) {
		this.role = role;
		this.status = status;
		this.firstName = firstName;
		this.lastName = lastName;
		this.login = login;
		this.password = password;
		this.impediments = impediments;
		this.sprintbacklogs = sprintbacklogs;
		this.projectparticipations = projectparticipations;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "nUserID", unique = true, nullable = false)
	public Integer getPersonID() {
		return this.personID;
	}

	public void setPersonID(Integer userID) {
		this.personID = userID;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "nRoleID", nullable = false)
	public Role getRole() {
		return this.role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "nStatusID", nullable = false)
	public Status getStatus() {
		return this.status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	@Column(name = "cFirstName", nullable = false, length = 30)
	public String getFirstName() {
		return this.firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	@Column(name = "cLastName", nullable = false, length = 30)
	public String getLastName() {
		return this.lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	@Column(name = "cLogin", unique = true, nullable = false, length = 20)
	public String getLogin() {
		return this.login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	@Column(name = "cPassword", length = 15)
	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@OneToMany(fetch = FetchType.EAGER, mappedBy = "user")
	public Set<Impediment> getImpediments() {
		return this.impediments;
	}

	public void setImpediments(Set<Impediment> impediments) {
		this.impediments = impediments;
	}

	@OneToMany(fetch = FetchType.EAGER, mappedBy = "user")
	public Set<Task> getSprintbacklogs() {
		return this.sprintbacklogs;
	}

	public void setSprintbacklogs(Set<Task> sprintbacklogs) {
		this.sprintbacklogs = sprintbacklogs;
	}

	@OneToMany(fetch = FetchType.EAGER, mappedBy = "person")
	public Set<ProjectParticipation> getProjectparticipations() {
		return this.projectparticipations;
	}

	public void setProjectparticipations(Set<ProjectParticipation> projectparticipations) {
		this.projectparticipations = projectparticipations;
	}

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }

        if (getClass() != obj.getClass()) {
            return false;
        }
        final Person other = (Person) obj;
        if(this.personID == null){
            if(other.getPersonID() != null){
                return false;
            }
        } else if(!this.personID.equals(other.getPersonID())){
            return false;
        }
        return true;

    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 47 * hash + (this.personID != null ? this.personID.hashCode() : 0);
        hash = 47 * hash + (this.firstName != null ? this.firstName.hashCode() : 0);
        return hash;
    }

}
